<!-- 通用：修改密码 -->
<template>
    <el-dialog title="修改密码" v-model="dialogVisible" append-to-body="true" width="550">
        <div class="">
        <div class="c-card" style="width: 500px;">
            <el-form :inline="false" label-width="8em" v-if="state.model">
                <in-input type="password" name="新密码" v-model="state.model.newPwd"></in-input>
                <in-input type="password" name="确认密码" v-model="state.model.newPwd2"></in-input>
            </el-form>
        </div>
    </div>
        <template #footer>
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="ok">确 定</el-button>
        </template>
    </el-dialog>
    
</template>

<script setup name="update-password">
import {reactive, ref} from "vue";
import InInput from "../../sa-frame/com/in/in-input";

const dialogVisible = ref(false);

// ------------------ 数据 ------------------
const state = reactive({
    model: {    // 数据 Model
        oldPwd: '',
        oldPwd2: '',
        newPwd: '',
        newPwd2: ''
    }
});

// ------------------ 函数 ------------------
// 提交表单 
const ok = function () {
    // 表单校验
    let model = state.model;
    sa.checkNull(model.newPwd && model.newPwd2, '请填写密码');
    sa.check(model.newPwd !== model.newPwd2, '新密码两次输入不一致');
    sa.check(model.newPwd.length < 4, '新密码请不要低于六位数');
    // 开始修改 
    emit('confirm',model.newPwd)
}

const open = function() {
    dialogVisible.value = true
}
const close = function() {
    dialogVisible.value = false
}
const emit = defineEmits(['confirm'])
// 对外开放函数 
defineExpose({
    ok: ok,
    open,
    close
});


</script>

<style scoped>

</style>
